package com.dkd.manage.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.dkd.common.annotation.Log;
import com.dkd.common.core.controller.BaseController;
import com.dkd.common.core.domain.AjaxResult;
import com.dkd.common.enums.BusinessType;
import com.dkd.manage.domain.StrategyDevice;
import com.dkd.manage.mapper.StrategyDeviceMapper;
import com.dkd.common.utils.poi.ExcelUtil;
import com.dkd.common.core.page.TableDataInfo;

/**
 * 策略设备关联Controller
 *
 * @author ruoyi
 * @date 2025-11-10
 */
@RestController
@RequestMapping("/manage/strategyDevice")
public class StrategyDeviceController extends BaseController
{
    @Autowired
    private StrategyDeviceMapper strategyDeviceMapper;

    /**
     * 查询策略设备关联列表
     */
    @PreAuthorize("@ss.hasPermi('manage:strategyDevice:list')")
    @GetMapping("/list")
    public TableDataInfo list(StrategyDevice strategyDevice)
    {
        startPage();
        List<StrategyDevice> list = strategyDeviceMapper.selectStrategyDeviceList(strategyDevice);
        return getDataTable(list);
    }

    /**
     * 根据策略ID查询设备关联列表
     */
    @PreAuthorize("@ss.hasPermi('manage:strategyDevice:list')")
    @GetMapping("/strategy/{strategyId}")
    public AjaxResult listByStrategyId(@PathVariable("strategyId") Long strategyId)
    {
        List<StrategyDevice> list = strategyDeviceMapper.selectStrategyDeviceByStrategyId(strategyId);
        return AjaxResult.success(list);
    }

    /**
     * 根据设备ID查询策略关联列表
     */
    @PreAuthorize("@ss.hasPermi('manage:strategyDevice:list')")
    @GetMapping("/device/{deviceId}")
    public AjaxResult listByDeviceId(@PathVariable("deviceId") Long deviceId)
    {
        List<StrategyDevice> list = strategyDeviceMapper.selectStrategyDeviceByDeviceId(deviceId);
        return AjaxResult.success(list);
    }

    /**
     * 导出策略设备关联列表
     */
    @PreAuthorize("@ss.hasPermi('manage:strategyDevice:export')")
    @Log(title = "策略设备关联", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, StrategyDevice strategyDevice)
    {
        List<StrategyDevice> list = strategyDeviceMapper.selectStrategyDeviceList(strategyDevice);
        ExcelUtil<StrategyDevice> util = new ExcelUtil<StrategyDevice>(StrategyDevice.class);
        util.exportExcel(response, list, "策略设备关联数据");
    }

    /**
     * 获取策略设备关联详细信息
     */
    @PreAuthorize("@ss.hasPermi('manage:strategyDevice:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(strategyDeviceMapper.selectStrategyDeviceById(id));
    }

    /**
     * 新增策略设备关联
     */
    @PreAuthorize("@ss.hasPermi('manage:strategyDevice:add')")
    @Log(title = "策略设备关联", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody StrategyDevice strategyDevice)
    {
        return toAjax(strategyDeviceMapper.insertStrategyDevice(strategyDevice));
    }

    /**
     * 修改策略设备关联
     */
    @PreAuthorize("@ss.hasPermi('manage:strategyDevice:edit')")
    @Log(title = "策略设备关联", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody StrategyDevice strategyDevice)
    {
        return toAjax(strategyDeviceMapper.updateStrategyDevice(strategyDevice));
    }

    /**
     * 删除策略设备关联
     */
    @PreAuthorize("@ss.hasPermi('manage:strategyDevice:remove')")
    @Log(title = "策略设备关联", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(strategyDeviceMapper.deleteStrategyDeviceByIds(ids));
    }
}